package com.hotcode;

/**
 * @Author: huangzhigao
 * @Date: 2023/2/25 15:40
 */
public class leecode48 {
    public void rotate(int[][] matrix) {
        int n = matrix.length;
        for (int i = 0; i < n; i++) {
            for (int j = i; j < n; j++) {
                int tmp = matrix[i][j];
                matrix[i][j] = matrix[j][i];
                matrix[j][i] = tmp;
            }
        }

        for (int[] rows : matrix) {
            reverse(rows);
        }
    }


    public void reverse(int[] nums) {
        int left = nums[0];
        int right = nums[nums.length - 1];
        while (left < right) {
            int tmp = nums[left];
            nums[left] = nums[right];
            nums[right] = tmp;
            left++;
            right--;
        }
    }
}
